﻿@using PersonBlog.Model
@using PersonBlog.Models

@model PWDManage.Model.QueryParam.QueryParamBase

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
    List<AgendaManageEntity> AgendaList = ViewBag.AgendaList == null ? new List<AgendaManageEntity>() : ViewBag.AgendaList;
    Result r = ViewBag.Result == null ? new Result() : ViewBag.Result;

    int TotalCount = ViewBag.TotalCount == null ? 0 : ViewBag.TotalCount;
}

<style>
    .btn { display: inline-block; padding: 6px 12px; margin-bottom: 0; font-size: 14px; font-weight: 400; line-height: 1.42857143; text-align: center; white-space: nowrap; vertical-align: middle; -ms-touch-action: manipulation; touch-action: manipulation; cursor: pointer; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; background-image: none; border: 1px solid transparent; border-radius: 4px; }
    .btn.active.focus, .btn.active:focus, .btn.focus, .btn:active.focus, .btn:active:focus, .btn:focus { outline: thin dotted; outline: 5px auto -webkit-focus-ring-color; outline-offset: -2px; }
    .btn.focus, .btn:focus, .btn:hover { color: #333; text-decoration: none; }
    .btn.active, .btn:active { background-image: none; outline: 0; -webkit-box-shadow: inset 0 3px 5px rgba(0,0,0,.125); box-shadow: inset 0 3px 5px rgba(0,0,0,.125); }
    .btn.disabled, .btn[disabled], fieldset[disabled] .btn { pointer-events: none; cursor: not-allowed; filter: alpha(opacity=65); -webkit-box-shadow: none; box-shadow: none; opacity: .65; }
    .btn-success { color: #fff; background-color: #5cb85c; border-color: #4cae4c; }
    .btn-success.active, .btn-success.focus, .btn-success:active, .btn-success:focus, .btn-success:hover, .open > .dropdown-toggle.btn-success { color: #fff; background-color: #449d44; border-color: #398439; }
    .btn-success.active, .btn-success:active, .open > .dropdown-toggle.btn-success { background-image: none; }
    .btn-success.disabled, .btn-success.disabled.active, .btn-success.disabled.focus, .btn-success.disabled:active, .btn-success.disabled:focus, .btn-success.disabled:hover, .btn-success[disabled], .btn-success[disabled].active, .btn-success[disabled].focus, .btn-success[disabled]:active, .btn-success[disabled]:focus, .btn-success[disabled]:hover, fieldset[disabled] .btn-success, fieldset[disabled] .btn-success.active, fieldset[disabled] .btn-success.focus, fieldset[disabled] .btn-success:active, fieldset[disabled] .btn-success:focus, fieldset[disabled] .btn-success:hover { background-color: #5cb85c; border-color: #4cae4c; }
    .btn-success .badge { color: #5cb85c; background-color: #fff; }
    .btn-warning { color: #fff; background-color: #f0ad4e; border-color: #eea236; }
    .btn-warning.active, .btn-warning.focus, .btn-warning:active, .btn-warning:focus, .btn-warning:hover, .open > .dropdown-toggle.btn-warning { color: #fff; background-color: #ec971f; border-color: #d58512; }
    .btn-warning.active, .btn-warning:active, .open > .dropdown-toggle.btn-warning { background-image: none; }
    .btn-warning.disabled, .btn-warning.disabled.active, .btn-warning.disabled.focus, .btn-warning.disabled:active, .btn-warning.disabled:focus, .btn-warning.disabled:hover, .btn-warning[disabled], .btn-warning[disabled].active, .btn-warning[disabled].focus, .btn-warning[disabled]:active, .btn-warning[disabled]:focus, .btn-warning[disabled]:hover, fieldset[disabled] .btn-warning, fieldset[disabled] .btn-warning.active, fieldset[disabled] .btn-warning.focus, fieldset[disabled] .btn-warning:active, fieldset[disabled] .btn-warning:focus, fieldset[disabled] .btn-warning:hover { background-color: #f0ad4e; border-color: #eea236; }
    .btn-warning .badge { color: #f0ad4e; background-color: #fff; }
    .btn-danger { color: #fff; background-color: #d9534f; border-color: #d43f3a; }
    .btn-danger.active, .btn-danger.focus, .btn-danger:active, .btn-danger:focus, .btn-danger:hover, .open > .dropdown-toggle.btn-danger { color: #fff; background-color: #c9302c; border-color: #ac2925; }
    .btn-danger.active, .btn-danger:active, .open > .dropdown-toggle.btn-danger { background-image: none; }
    .btn-danger.disabled, .btn-danger.disabled.active, .btn-danger.disabled.focus, .btn-danger.disabled:active, .btn-danger.disabled:focus, .btn-danger.disabled:hover, .btn-danger[disabled], .btn-danger[disabled].active, .btn-danger[disabled].focus, .btn-danger[disabled]:active, .btn-danger[disabled]:focus, .btn-danger[disabled]:hover, fieldset[disabled] .btn-danger, fieldset[disabled] .btn-danger.active, fieldset[disabled] .btn-danger.focus, fieldset[disabled] .btn-danger:active, fieldset[disabled] .btn-danger:focus, fieldset[disabled] .btn-danger:hover { background-color: #d9534f; border-color: #d43f3a; }
    .btn-danger .badge { color: #d9534f; background-color: #fff; }

    .pagination { margin-top: 0px; }

    .bs-example4 { margin: 10px 0; }

    .form-control1 { width: 70%; }
    .controllabel { font-size: 16px; width: 20%; color: #999; font-weight: bold; margin-right: 10px; text-align: right; height: 40px; line-height: 40px; }

    .pagecount { border: 1px solid #e0e0e0; padding: 5px 8px; color: #616161; background: #fff; box-shadow: none !important; width: 50px; font-size: 0.85em; font-weight: 400; height: 34px; border-radius: 0; -webkit-appearance: none; }

    #maxPageCount { font-weight: bold; font-size: 16px; }
</style>

<input id="msg" type="hidden" value="@r.Message" />
<div class="col-md-12 graphs">
    <div class="xs">
        <h3>日程管理</h3>
        @using (Html.BeginForm("List", "AgendaManage", FormMethod.Post, new { @class = "form-horizontal", id = "form" }))
        {
            @Html.HiddenFor(model => model.PageCount, new { id = "pageCount" });
            @Html.Hidden("TotalCount", TotalCount, new { id = "totalCount" });
            @Html.HiddenFor(model => model.PageSize, new { id = "pageSize" });

            <div class="row">
                <div class="col-md-4 grid_box1">
                    <label for="focusedinput" class="controllabel">查询</label>
                    @Html.TextBoxFor(m => m.Name, new { @class = "form-control1", placeholder = "程序名称/用户名" })
                </div>
                <div class="col-md-4 grid_box1">
                    <button class="btn btn-success" id="btn" type="submit">查询</button>
                </div>
                <div class="clearfix"> </div>
            </div>
        }
        <div class="bs-example4" data-example-id="contextual-table">
            <table class="table">
                <thead>
                    <tr>
                        <th>全选</th>
                        <th>主题</th>
                        <th>开始时间</th>
                        <th>结束时间</th>
                        <th>创建时间</th>
                        <th>备注</th>
                    </tr>
                </thead>
                <tbody>
                    @if (AgendaList.Count > 0)
                    {
                        int num = 0;
                        foreach (AgendaManageEntity item in AgendaList)
                        {
                            if (num % 2 == 0)
                            {
                                <tr class="info">
                                    <th scope="row"><input type="checkbox" name="cbx" value="@item.ID" /></th>
                                    <td>@item.Topic</td>
                                    <td>@item.StartTime</td>
                                    <td>@item.EndTime</td>
                                    <td>@item.CreateTime</td>
                                    <td><button class="btn btn-warning" onclick="window.location.href='@Url.Action("Create")?Id=@item.ID'">编辑</button></td>
                                </tr>
                            }
                            else
                            {
                                <tr>
                                    <th scope="row"><input type="checkbox" name="cbx" value="@item.ID" /></th>
                                    <td>@item.Topic</td>
                                    <td>@item.StartTime</td>
                                    <td>@item.EndTime</td>
                                    <td>@item.CreateTime</td>
                                    <td><button class="btn btn-warning" onclick="window.location.href='@Url.Action("Create")?Id=@item.ID'">编辑</button></td>
                                </tr>
                            }
                            num++;
                        }
                    }
                </tbody>
            </table>
        </div>
        <button class="btn btn-success" onclick="window.location.href='@Url.Action("Create")'">新建</button>
        <button class="btn btn-danger" onclick="dele();">删除</button>
        <div class="navright" style="float:right; margin-top:0;">
            <div class="btn-group">
                <button type="button" class="btn btn-info" onclick="pageChange('A');">首页</button>
                <button type="button" class="btn btn-info" onclick="pageChange('-');">上一页</button>
                <button type="button" class="btn btn-info" onclick="pageChange('+');">下一页</button>
                <button type="button" class="btn btn-info" onclick="pageChange('Z');">末页</button>
               
            </div>
        </div>
    </div>
</div>



<script>

    $(document).ready(function () {
        var msg = $("#msg").val();
        if (msg != "") {
            layer.msg(msg);
        }
        var currPageIndex = $("#pageCount").val();
        var totalCount = $("#totalCount").val();
        var pageSize = $("#pageSize").val();
        var MaxPageCount = Math.ceil(parseInt(totalCount) / parseInt(pageSize));
        $("#maxPageCount").text(MaxPageCount.toString());
        $("#page").val(currPageIndex);
    })

    function dele() {
        var ids = "";
        $("input[name='cbx']").each(function () {
            var obj = $(this);
            if (this.checked == true) {
                ids += $(this).val() + ",";
            }
        });
        window.location.href = '@Url.Action("Delete","AgendaManage")?ids=' + ids;
    }

    function pageChange(type)
    {
        var currPageIndex = $("#pageCount").val();
        var totalCount = $("#totalCount").val();
        var pageSize=$("#pageSize").val();
        var MaxPageCount = Math.ceil(parseInt(totalCount) / parseInt(pageSize));
        var pageIndex = 0;
        switch(type)
        {
            case "A":
                pageIndex = 1;
                break;
            case "-":
                pageIndex = parseInt(currPageIndex) - 1;
                if(pageIndex<=0)
                {
                    layer.msg("已经是第一页！");
                    return false;
                }
                break;
            case "+":
                pageIndex = parseInt(currPageIndex) + 1;
                if (pageIndex > MaxPageCount) {
                    layer.msg("已经是最后一页！");
                    return false;
                }
                break;
            case "Z":
                pageIndex = MaxPageCount;
                break;
            case "T":
                pageIndex = parseInt($("#page").val());
                if(pageIndex>MaxPageCount || pageIndex<=0)
                {
                    layer.msg("输入的页码不在合理范围内，请重新输入！");
                    return false;
                }
                break;
        }
        $("#pageCount").val(pageIndex);
        $("#btn").click();
    }
</script>
<!-- /#page-wrapper -->
